package org.example.examsystem.controller;

import org.example.examsystem.entity.StudentExam;
import org.example.examsystem.entity.UnansweredExam;
import org.example.examsystem.service.StudentExamService;
import org.example.examsystem.service.UnansweredExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/student/exams")
public class StudentExamController {

    @Autowired
    private StudentExamService studentExamService;
    @Autowired
    private UnansweredExamService unansweredExamService;

    @GetMapping("/answered")
    public Page<StudentExam> getAnsweredExams(@RequestParam(defaultValue = "0") int page,
                                              @RequestParam(defaultValue = "10") int size) {
        Pageable pageable = PageRequest.of(page, size);
        return studentExamService.getAnsweredExams(pageable);
    }

    @GetMapping("/unanswered")
    public Page<UnansweredExam> getUnansweredExams(@RequestParam(defaultValue = "0") int page,
                                                   @RequestParam(defaultValue = "10") int size,
                                                   @RequestParam(required = false) Integer classid) {
        Pageable pageable = PageRequest.of(page - 1, size);
        return unansweredExamService.getUnansweredExams(pageable,classid);
    }
}